<?php if ($this->_var['full_page']): ?>
<?php echo $this->fetch('pageheader.htm'); ?>
<?php echo $this->smarty_insert_scripts(array('files'=>'../js/utils.js,listtable.js')); ?>

<div class="form-div">
  <form action="javascript:search_giftcard()" name="searchForm">
    <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
    <?php echo $this->_var['lang']['keyword']; ?> <input type="text" name="giftcard_name" size="15" />
    <input type="submit" value="<?php echo $this->_var['lang']['button_search']; ?>" class="button" />
  </form>
</div>
<script language="JavaScript">
    function search_giftcard()
    {
        listTable.filter['giftcard_name'] = Utils.trim(document.forms['searchForm'].elements['giftcard_name'].value);
        listTable.filter['page'] = 1;
        
        listTable.loadList();
    }
</script>


<form method="post" action="gift_card.php?act=list" name="listForm" id="listForm" autocomplete="off">
    <div class="list-div" id="listDiv">
<?php endif; ?>
        <table cellpadding="3" cellspacing="1">
            <tr>
                <th>选择</th>
                <th>id</th>
                <th>礼品卡序列号</th>
                <th>礼品卡余额</th>
                <th>礼品卡金额</th>
                <th>使用会员</th>
                <th>使用时间</th>
                <th>到期时间</th>
                <th>是否启用</th>
                <th>操作</th>
            </tr>

            <?php $_from = $this->_var['gift_card_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'user_bonus');if (count($_from)):
    foreach ($_from AS $this->_var['user_bonus']):
?>
            <tr>
                <td align="center"><input name="bonus_id" type="checkbox" value="<?php echo $this->_var['user_bonus']['bonus_id']; ?>" class="np"></td>
                <td align="center"><?php echo $this->_var['user_bonus']['bonus_id']; ?></td>
                <td align="center"><?php echo $this->_var['user_bonus']['bonus_number']; ?></td>
                <td align="center"><?php echo $this->_var['user_bonus']['bonus_balance']; ?></td>
                <td align="center"><?php echo $this->_var['user_bonus']['type_money']; ?></td>
                <td align="center"><?php echo $this->_var['user_bonus']['user_name']; ?></td>
                <td align="center"><?php echo $this->_var['user_bonus']['used_time']; ?></td>
                <td align="center"><?php echo $this->_var['user_bonus']['use_end_date']; ?></td>
                <td align="center"><?php if ($this->_var['user_bonus']['is_confirmed'] == 0): ?><font style="color:red;font-weight:bold;">未启用</font>
                    <?php else: ?><font style="color:#3F0;font-weight:bold;">已启用</font><?php endif; ?></td>
                <td align="center">
                    <a href="javascript:;" onclick="listTable.using(<?php echo $this->_var['user_bonus']['bonus_id']; ?>, '你确定要启用这条记录吗？')">启用</a>&nbsp;&nbsp;&nbsp;|
                    <a href="javascript:;" onclick="listTable.stop(<?php echo $this->_var['user_bonus']['bonus_id']; ?>, '你确定要停用这条记录吗？')">停用</a>&nbsp;&nbsp;&nbsp;|
                    <a href="javascript:;" onclick="listTable.remove(<?php echo $this->_var['user_bonus']['bonus_id']; ?>, '你确定要删除这条记录吗？')">删除</a>
                </td>
            </tr>
            <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
            <tr>
                <td align="left" nowrap="true" colspan="6" style="padding-left:20px;">
                    <a href="javascript:;" id="sel_all">全选</a>&nbsp;&nbsp;&nbsp;|
                    <a href="javascript:;" id="cancel_all">取消</a>&nbsp;&nbsp;&nbsp;|
                    <a href="javascript:;" id="using_all">启用</a>&nbsp;&nbsp;&nbsp;|
                    <a href="javascript:;" id="stop_all">停用</a>&nbsp;&nbsp;&nbsp;|
                    <a href="javascript:;" id="delete_all">删除</a>
                </td>
            </tr>
            <tr>
                <td align="right" nowrap="true" colspan="6">
                <?php echo $this->fetch('page.htm'); ?>
                </td>
            </tr>
    
        </table>
        
    <?php if ($this->_var['full_page']): ?>
    </div>
</form>

	
<script type="text/javascript" language="javascript">
    <!--
    listTable.recordCount = <?php echo $this->_var['record_count']; ?>;
    listTable.pageCount = <?php echo $this->_var['page_count']; ?>;

    <?php $_from = $this->_var['filter']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('key', 'item');if (count($_from)):
    foreach ($_from AS $this->_var['key'] => $this->_var['item']):
?>
    listTable.filter.<?php echo $this->_var['key']; ?> = '<?php echo $this->_var['item']; ?>';
    <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>

    
    onload = function()
    {
        // 开始检查订单
        startCheckOrder();
    }
    
    //-->
</script>

<script language="javascript" src="/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" language="javascript">
$(function(){
    $('#sel_all').live('click',function(){       //选择所有checkbox
        $("input[name='bonus_id']").attr("checked",true);
    });
        
    $('#cancel_all').live('click',function(){        //取消所有checkbox
        $("input[name='bonus_id']").attr("checked",false);
    });
    
    function checkall(){
        var str="";
        $("[name='bonus_id']:checked").each(function(){    //checked选中的状态
            str= str + $(this).val()+',';
        })
        return str.substring(0,str.length-1);    //substring(start,stop)去掉逗号( ,)
    }
    
    $("#delete_all").live('click',function(){
        if(checkall()=="")
        {
            alert("请选择删除对象!");
            return false;
        }
        if(confirm('确定删除这些礼品卡吗？'))
        {
            $.ajax({
                type:"POST",
                cache:"false",
                url:"gift_card_model.php",
                data:'delete_bonus_id='+checkall(),
                dataType:'text',
                success:function(data)
                {
                    alert(data);
                    window.location.reload();
                },
                error:function()
                {
                    alert("删除失败!");
                }
            })
        }
    })
    
    $("#stop_all").live('click',function(){
        if(checkall()=="")
        {
            alert("请选择停用对象!");
            return false;
        }
        if(confirm('确定停用这些礼品卡吗？'))
        {
            $.ajax({
                type:"POST",
                cache:"false",
                url:"gift_card_model.php",
                data:'stop_bonus_id='+checkall(),
                dataType:'text',
                success:function(data)
                {
                    alert(data);
                    window.location.reload();
                },
                error:function()
                {
                    alert("停用失败!");
                }
            })
        }
    })
    
    $("#using_all").live('click',function(){
        if(checkall()=="")
        {
            alert("请选择启用对象!");
            return false;
        }
        if(confirm('确定启用这些礼品卡吗？'))
        {
            $.ajax({
                type:"POST",
                cache:"false",
                url:"gift_card_model.php",
                data:'using_bonus_id='+checkall(),
                dataType:'text',
                success:function(data)
                {
                    alert(data);
                    window.location.reload();
                },
                error:function()
                {
                    alert("启用失败!");
                }
            })
        }
    })
});
</script>
    <?php echo $this->fetch('pagefooter.htm'); ?>
    <?php endif; ?>
